#include<iostream>
#include<signal.h>
#include<unistd.h>

using namespace std;

void print_pending(const sigset_t& pending)
{
    cout << getpid() << ": ";
    for(int i = 31; i >= 1; i--)
    {
        int n = sigismember(&pending, i);
        if(n)
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout << "\n\n";
}

void test_1()
{
    //初始化位图
    sigset_t bset, oset;
    sigemptyset(&bset);
    sigemptyset(&oset);
    //将位图1-31全设为1
    for(int i = 1; i <= 31; i++)
    {
        sigaddset(&bset, i);
    }
    //选择阻塞1-31信号
    sigprocmask(SIG_SETMASK, &bset, &oset);

    //获取并打印pending
    sigset_t pending;
    while(true)
    {
        int n = sigpending(&pending);
        if(n < 0) continue;
        print_pending(pending);
        sleep(1);
    }


}

int main()
{
    test_1();

    return 0;
}